<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>
			<%= title %>
		</title>
		<%- include('../include/stylelist') %>
		<%- include('../include/scriptlist') %>
	</head>

	<body class="layui-layout-body">
		<div class="layui-layout layui-layout-admin">
			<%- include('../include/head',{title:'woyao.tv'})  %>
			<%- include('../include/left',{title:'woyao.tv'})  %>

			<div class="layui-body">
				<!-- 内容主体区域 -->
				<div class="layui-container">
					<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
						<legend>请输入友情链接（必须加上http://或 https://）</legend>
					</fieldset>
					<div style="padding: 15px;">
						<table class="layui-hide" id="demo" lay-filter="demo"></table>

						<script type="text/html" id="barDemo">
							<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
							<a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
							<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="filter">未通过</a>
							<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
						</script>

						<!-- 投稿类型 -->
						<script type="text/html" id="ContentTypeTpl">
							{{# if(d.ContentType == '3'){ }} 文本+视频 {{# } else if(d.ContentType == '2') { }} 文本+图片 {{# }else if(d.ContentType == '1') { }} 纯文本 {{# } }}
						</script>

						<!-- 投稿时间 -->
						<script type="text/html" id="SubTimeTpl">
							{{d.SubTime = d.SubTime.replace(/T/,' ').replace('.000Z','')}}
						</script>

						<!-- 审核状态 -->
						<script type="text/html" id="StatusTpl">
							{{# if(d.Status == '2'){ }} 通过 {{# } else if(d.Status == '0') { }} 未审核 {{# }else if(d.Status == '1') { }} 未通过 {{# } }}
						</script>
					</div>
					<div class="layui-form">
						<div class="layui-form-item layui-form-text">
							<label class="layui-form-label">网站描述</label>
							<div class="layui-input-block">
								<textarea placeholder="一行填写一个" name="linkoption" class="layui-textarea"><%= Config.WebsiteDescription %></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit="" id="linkConfig">保存</button>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="layui-footer">
				<!-- 底部固定区域 -->
				© WoYao.Tv - 底部固定区域
			</div>
		</div>
		<script>
			//JavaScript代码区域
			layui.use('element', function() {
				var element = layui.element;
			});
			layui.use('table', function() {
				var table = layui.table;
				table.render({
					elem: '#demo',
					cols: [
						[ //标题栏
							{
								field: 'linkname',
								title: '名字',
								width: 150
							}, {
								field: 'linkurl',
								title: '链接',
								width: 200
							}
						]
					],
					data: <%- Config %>
						//,skin: 'line' //表格风格

						,
					even: true //,page: true //是否显示分页
					//,limits: [5, 7, 10]
					//,limit: 5 //每页默认显示的数量
				});
				//监听表格复选框选择
				table.on('checkbox(demo)', function(obj) {
					console.log(obj)
				});
				//监听工具条
				table.on('tool(demo)', function(obj) {
					var laydata = obj.data;
					if(obj.event === 'detail') {
						layer.msg('ID：' + laydata.Sub_id + ' 的查看操作');
					} else if(obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							$.ajax({
								type: "post",
								url: "/admin/api/index/del",
								async: true,
								data: {
									"id": laydata.Sub_id
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('删除成功')
										obj.del();
										layer.close(index);
									} else {
										layer.msg(data.msg)
									}
								}
							});
						});
					} else if(obj.event === 'pass') {
						$.ajax({
							type: "post",
							url: "/admin/api/index/pass",
							async: true,
							data: {
								"id": laydata.Sub_id
							},
							success: function(data) {
								if(data.code == 0) {
									layer.msg('审核通过')
									obj.update({
										Status: 2
									});
								} else {
									layer.msg(data.msg)
								}
							}
						});
					}
				});
				//监听单元格编辑

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('idTest');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.demoTable .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
			});
			//保存配置
			$("#linkConfig").click(function() {
				console.log($("[name=linkoption]").val())
				var option = {
					linkoption: $("[name=linkoption]").val()
				}
				//				Wo.SiteConfig(option)
			})
		</script>
	</body>

</html>